package Fulbito.SERVLET;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;

import Fulbito.EXCEPCION.DAOExcepcion;
import Fulbito.MODELO.Distrito;
import Fulbito.MODELO.Local;
import Fulbito.NEGOCIO.LocalNEG;


/**
 * Servlet implementation class ServletCargaLocales
 */
@WebServlet("/ServletCargaLocales")
public class ServletCargaLocales extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletCargaLocales() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		int iintCodDistrito = Integer.parseInt(request.getParameter("productCode"));
			LocalNEG dao =new LocalNEG();
			Collection<Local> local = new ArrayList<Local>(); 
			try {
				local = dao.ListarCombo(iintCodDistrito);
			} catch (DAOExcepcion e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				    for (Local product : local) 
				    {
				        out.printf("<option value='%1s'>%2s</option>", product.getCodLocal(), product.getNombre());
				    }
				} finally 
				{
					out.close();
				}
	
	}

	protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException, DAOExcepcion {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int iintCodDistrito = Integer.parseInt(request.getParameter("productCode"));
	LocalNEG dao =new LocalNEG();
	Collection<Local> local = new ArrayList<Local>(); 
	local = dao.ListarCombo(iintCodDistrito);
	try {
		    for (Local product : local) 
		    {
		        out.printf("<option value='%1s'>%2s</option>", product.getCodLocal(), product.getNombre());
		    }
		} finally 
		{
			out.close();
		}
	}

}
